package com.meizi.mall.product.web;

import com.meizi.mall.product.entity.CategoryEntity;
import com.meizi.mall.product.service.CategoryService;
import com.meizi.mall.product.vo.CatalogL2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author meizi
 * @email enjoymeizi@gmail.com
 * @date 2021/1/20 17:50
 */
@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;

    @GetMapping({"/", "index", "index.html"})
    public String index(Model model) {
        List<CategoryEntity> categories = categoryService.getLevel1Cate();
        model.addAttribute("categories", categories);
        return "index";
    }
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String,List<CatalogL2Vo>> catalogJson(){
        return categoryService.catalogJson();
    }
}
